package com.sgcc.ln.pmos.e_ln_mall.bean;

import android.text.TextUtils;

import java.util.Calendar;


public class DataSelect {
    private String startdata;
    private String enddata;

    public String getStartdata() {
        return startdata;
    }

    public void setStartdata(String startdata) {
        Calendar calendar = Calendar.getInstance();
        int month = calendar.get(Calendar.MONTH) + 1;
        if (startdata.contains("-")) {
            this.startdata = startdata + "-01";
        } else if (startdata.contains("季度")) {
            startdata.replace("季度", "");
            String[] startstr = startdata.split("年第");
            if (TextUtils.equals("1", startstr[1])) {
                if (month > 1) {
                    this.startdata = startstr[0] + "-0" + month+"-01";
                } else {
                    this.startdata = startstr[0] + "-01"+"-01";
                }
            } else if (TextUtils.equals("2", startstr[1])) {
                if (month > 4) {
                    this.startdata = startstr[0] + "-0" + month+"-01";
                } else {
                    this.startdata = startstr[0] + "-04"+"-01";
                }
            } else if (TextUtils.equals("3", startstr[1])) {
                if (month > 7) {
                    this.startdata = startstr[0] + "-0" + month+"-01";
                } else {
                    this.startdata = startstr[0] + "-07"+"-01";
                }
            } else {
                if (month > 10) {
                    this.startdata = startstr[0] + "-" + month+"-01";
                } else {
                    this.startdata = startstr[0] + "-10"+"-01";
                }
            }
        } else {
            if (month<10) {
                this.startdata = startdata+"-0"+month+"-01";
            }else{
                this.startdata = startdata+"-"+month+"-01";
            }
        }
    }

    public String getEnddata() {
        return enddata;
    }

    public void setEnddata(String enddata) {

//        Calendar calendar = Calendar.getInstance();
//        int month = calendar.get(Calendar.MONTH) + 1;

        Calendar cal = Calendar.getInstance();



        if (enddata.contains("-")) {

            int year = Integer.parseInt(enddata.substring(0,4));  //截取出年份，并将其转化为int
            int month1 = Integer.parseInt(enddata.substring(5,7));    //截去除月份，并将其转为int

            cal.set(Calendar.YEAR,year);    //设置年份
            cal.set(Calendar.MONTH, month1-1);  //设置月份
            int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
            this.enddata = enddata + "-"+lastDay;
        } else if (enddata.contains("季度")) {
            enddata.replace("季度", "");
            String[] startstr = enddata.split("年第");
            int year = Integer.parseInt(enddata.substring(0,4));  //截取出年份，并将其转化为int
            if (TextUtils.equals("1", startstr[1])) {
                int month1 = 3;    //截去除月份，并将其转为int
                cal.set(Calendar.YEAR,year);    //设置年份
                cal.set(Calendar.MONTH, month1-1);  //设置月份
                int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
                this.enddata = startstr[0] + "-03-" +lastDay;
            } else if (TextUtils.equals("2", startstr[1])) {
                int month1 = 6;    //截去除月份，并将其转为int
                cal.set(Calendar.YEAR,year);    //设置年份
                cal.set(Calendar.MONTH, month1-1);  //设置月份
                int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
                this.enddata = startstr[0] + "-06-" +lastDay;
            } else if (TextUtils.equals("3", startstr[1])) {
                int month1 = 9;    //截去除月份，并将其转为int
                cal.set(Calendar.YEAR,year);    //设置年份
                cal.set(Calendar.MONTH, month1-1);  //设置月份
                int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
                this.enddata = startstr[0] + "-09-" +lastDay;
            } else {
                int month1 = 12;    //截去除月份，并将其转为int
                cal.set(Calendar.YEAR,year);    //设置年份
                cal.set(Calendar.MONTH, month1-1);  //设置月份
                int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
                this.enddata = startstr[0] + "-12-" +lastDay;
            }
        } else {
            this.enddata = enddata+"-12-31";
        }
    }
}
